<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="js/jquery.js"></script>
<body>
<div id="div1" >
    <ul id="ul2" >
        <li id="li3" >
            <button id="btn4" type="button">button</button>
        </li>
    </ul>

</div>
<a id="a1" href="#">hahaha</a>
<!----------------------测试2----------------------->
<div id="t2div">
    <ul id="t2ul">
        <li id="t2li">
            <button id="t2btn" type="button">button2</button>
        </li>
    </ul>
</div>
<script>
    var haha=["div1","ul2","li3","btn4"];
    for(var i=0;i<4;i++){
        document.getElementById(haha[i]).addEventListener("click",function (e) {
            console.log(this.id);
        },true)
    }
    ///以下为event.preventDefault();
    document.getElementById("a1").addEventListener("click",function (e) {
        console.log("跳转"+this.href);
        e.preventDefault();
    })
////////////////////////////测试2/////////////////////////////
    var haha2=["t2div","t2ul","t2li","t2btn"];
    for(var i=0;i<4;i++){
       $("#"+haha2[i]).on("click",function () {
            console.log(this.id);
        })
    }
</script>
</body>
</html>